package com.stx.chat.controller;

import com.stx.chat.entity.User;
import com.stx.chat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/register")
    public HashMap register(String username,String password){


        boolean success = userService.register(username,password);

        HashMap<String,Object> resultMap = new HashMap<>();
        resultMap.put("isSuccess",success);
        return resultMap;

    }

    @RequestMapping("/login")
    public HashMap login(String username,String password){

        HashMap<String,Object> resultMap = new HashMap<>();
        User user = userService.login(username,password);
        if (user!=null){
            resultMap.put("isSuccess","true");
            resultMap.put("user",user);
        }else {
            resultMap.put("isSuccess","false");
        }

        return resultMap;
    }



}
